package edu.luc.cs.trull.swing;

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;

/**
 * A visual component that provides a user interface consisting of
 * a button panel.  There is one button for each String event label specified
 * in the constructor argument.
 */
public class InputPanel extends ActionEventAdapter implements VisualComponent {

  /**
   * The panel that contains the buttons.
   */
  protected final JPanel buttonPanel = new JPanel();

  /**
   * Constructs an input panel with one button for each label in the array.
   * @param labels the labels for the buttons.
   */
  public InputPanel(final String[] labels) {
    buttonPanel.setLayout(new GridLayout(0, 1));
    for (int i = 0; i < labels.length; i ++) {
      JButton button = new JButton(labels[i]);
      buttonPanel.add(button);
      button.addActionListener(this);
    }
  }

  public JComponent getView() { return buttonPanel; }
}
